1
|
|
|
import { Move } from './../../../assets/data/moves.d'; |
2
|
|
|
import { GameDataService } from './../../data/gameData.service'; |
3
|
|
|
import { ValueAccessorBase } from './../abstract/ValueAccessorBase'; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
Copyright 2018 June Hanabi |
7
|
|
|
|
8
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); |
9
|
|
|
you may not use this file except in compliance with the License. |
10
|
|
|
You may obtain a copy of the License at |
11
|
|
|
|
12
|
|
|
http://www.apache.org/licenses/LICENSE-2.0 |
13
|
|
|
|
14
|
|
|
Unless required by applicable law or agreed to in writing, software |
15
|
|
|
distributed under the License is distributed on an "AS IS" BASIS, |
16
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17
|
|
|
See the License for the specific language governing permissions and |
18
|
|
|
limitations under the License. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
import { Component, Input } from '@angular/core'; |
22
|
|
|
import { PokemonDBService } from '../../data/pokemonDB.service'; |
23
|
|
|
|
24
|
|
|
import { |
25
|
|
|
NG_VALUE_ACCESSOR, |
26
|
|
|
} from '@angular/forms'; |
27
|
|
|
|
28
|
|
|
declare var window: { |
29
|
|
|
require: any; |
30
|
|
|
}; |
31
|
|
|
|
32
|
|
|
const _ = window.require("lodash"); |
33
|
|
|
|
34
|
|
|
@Component({ |
35
|
|
|
selector: 'select-moves', |
36
|
|
|
templateUrl: './select-moves.component.pug', |
37
|
|
|
styleUrls: ['./select-moves.component.scss'], |
38
|
|
|
providers: [ |
39
|
|
|
{ provide: NG_VALUE_ACCESSOR, useExisting: SelectMovesComponent, multi: true } |
40
|
|
|
], |
41
|
|
|
}) |
42
|
|
|
export class SelectMovesComponent extends ValueAccessorBase<string> { |
43
|
|
|
|
44
|
|
|
constructor( |
45
|
|
|
public gd: GameDataService, |
46
|
|
|
public pdb: PokemonDBService |
47
|
|
|
) { |
48
|
|
|
super(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
@Input() |
52
|
|
|
public disabled: boolean = false; |
53
|
|
|
|
54
|
|
|
@Input() |
55
|
|
|
public species: number | null = null; |
56
|
|
|
|
57
|
|
|
get pokemonData() { |
58
|
|
|
if(this.species == null) |
59
|
|
|
return undefined; |
60
|
|
|
|
61
|
|
|
return this.pdb.pokemon[this.species]; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
get movesList() { |
65
|
|
|
|
66
|
|
|
// Gather applicable Learnset (If Any) |
67
|
|
|
let learnset = []; |
68
|
|
|
if(this.pokemonData !== undefined && this.pokemonData.initial !== undefined) |
69
|
|
|
for (const learn of this.pokemonData.initial) { |
70
|
|
|
learnset.push({ |
71
|
|
|
name: `Level: 1 - ${learn.name}`, |
72
|
|
|
ind: learn.ind |
73
|
|
|
}); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
if(this.pokemonData !== undefined && this.pokemonData.moves !== undefined) |
77
|
|
|
for (const learn of this.pokemonData.moves) { |
78
|
|
|
learnset.push({ |
79
|
|
|
name: `Level: ${learn.level} - ${learn.move.name}`, |
80
|
|
|
ind: learn.move.ind |
81
|
|
|
}); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
// Gather applicable TM & HM's (If Any) |
85
|
|
|
let tmHms = []; |
86
|
|
|
if(this.pokemonData !== undefined && this.pokemonData.tmHm !== undefined) |
87
|
|
|
for (const tm of this.pokemonData.tmHm) { |
88
|
|
|
tmHms.push({ |
89
|
|
|
name: `${tm.tm.name}`, |
90
|
|
|
ind: tm.ind |
91
|
|
|
}); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
const moves = this.gd.file("moves").data; |
95
|
|
|
|
96
|
|
|
let moveListReg = _.filter(moves, (value: Move) => { |
97
|
|
|
if (!value.glitch) |
98
|
|
|
return true; |
99
|
|
|
|
100
|
|
|
return false; |
101
|
|
|
}); |
102
|
|
|
|
103
|
|
|
moveListReg = _.sortBy(moveListReg, ['name']); |
104
|
|
|
|
105
|
|
|
let moveListGlitch = _.filter(moves, (value: Move) => { |
106
|
|
|
if (value.glitch) |
107
|
|
|
return true; |
108
|
|
|
|
109
|
|
|
return false; |
110
|
|
|
}); |
111
|
|
|
|
112
|
|
|
moveListGlitch = _.sortBy(moveListGlitch, ['name']); |
113
|
|
|
|
114
|
|
|
const ret = [ |
115
|
|
|
{ name: "--- All Regular Moves ---", ind: 0x00, disable: true }, |
116
|
|
|
...moveListReg, |
117
|
|
|
{ name: "--- All Glitch Moves ---", ind: 0x00, disable: true }, |
118
|
|
|
...moveListGlitch, |
119
|
|
|
]; |
120
|
|
|
|
121
|
|
|
if(tmHms.length > 0) { |
122
|
|
|
ret.unshift(...tmHms); |
123
|
|
|
ret.unshift({name: "--- Learnable TM/HMs ---", ind: 0x00, disable: true}); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
if(learnset.length > 0) { |
127
|
|
|
ret.unshift(...learnset); |
128
|
|
|
ret.unshift({name: "--- Learnable Moves ---", ind: 0x00, disable: true}); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
return ret; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
getTooltip(move: any) { |
135
|
|
|
const moveData = this.pdb.moves[move.ind]; |
136
|
|
|
|
137
|
|
|
if(moveData === undefined || moveData.glitch) |
138
|
|
|
return ""; |
139
|
|
|
|
140
|
|
|
const power = (moveData.power && moveData.power > 1) ? moveData.power : "---"; |
141
|
|
|
const type = (moveData.type) ? _.startCase(_.lowerCase(moveData.type.name)) : "---"; |
142
|
|
|
const accuracy = (moveData.accuracy) ? `${moveData.accuracy}%` : "---"; |
143
|
|
|
const pp = (moveData.pp) ? moveData.pp : "---"; |
144
|
|
|
|
145
|
|
|
return `Power:${power} Type:${type} Accuracy:${accuracy} PP:${pp}`; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
movesTracking(index: number) { |
149
|
|
|
return `${index}-${this.species}`; |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|